package com.example.demo11.controller;

import com.example.demo11.entity.Role;
import com.example.demo11.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;
     /*增加用户*/
    @PutMapping("/emp/add")
    public String add(Role user) {
        roleService.addUser(user);
        return "增加用户成功";
    }

    /* 更新用户*/
    @PostMapping("/emp/update")
    public int update(Role user) {
        return roleService.updateUser(user);
    }

     /* 根据id查找信息*/
    @GetMapping("/emp/findId/{id}")
    public Role findById(@PathVariable("id") Integer id) {
        return roleService.findById(id);
    }

     /* 根据id删除信息*/
    @DeleteMapping("/emp/delete/{id}")
    public String deleteById(@PathVariable("id") Integer id) {
        roleService.deleteId(id);
        return "删除成功";
    }

    /* 展示所有用户*/
    @GetMapping("/emp/{page}")
    public List<Map<String, Object>> findAll(@PathVariable("page") Integer page) {
        return roleService.findAll(page);
    }

}